<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Excel;

class ExcelController extends Controller
{
    // excel 文件导出功能

    public function export(){
        $cellData = [
          ['学号','姓名','成绩'],
          ['1001','王大锤','98'],
          ['1002','王小锤','99'],
          ['1003','张不正','10'],
          ['1004','歪嘴','10'],
        ];
        Excel::create(iconv('UTF-8', 'GBK', '学生成绩'),function($excel) use ($cellData)
        {
            $excel->sheet('score',function($sheet) use ($cellData){

                $sheet->rows($cellData);
            });

        })->store('xls')->export('xls');
    }


    //excel 文件导入功能

    public function import()
    {

        $filePath = 'storage/exports/'.iconv('UTF-8', 'GBK', '学生成绩').'.xls';

        Excel::load($filePath, function($reader) {
            $data = $reader->all();
            dd($data);
        });

    }

}
